package com.TeamJigsaw.DanteTrail.Views;

import java.awt.Dimension;
import java.awt.Graphics;

import javax.swing.*;

import com.TeamJigsaw.DanteTrail.Views.Interfaces.ShopViewInterface;
import net.miginfocom.swing.MigLayout;
import javax.swing.border.TitledBorder;
import javax.swing.event.ChangeListener;

import java.awt.event.ActionListener;
import java.awt.Color;

public class ShopView extends JPanel implements ShopViewInterface{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JSpinner spinner;
	private JLabel currentFood, currentAmmo, currentClothes, currentWheels, currentTongues, currentOxen, currentAxels, currentMoney;
	private String item;
	private String htmlStart, htmlEnd;
	private JButton buyButton, nextButton;
	private JLabel label;
	private JLabel label_1;
	private JLabel label_2;
	private JLabel lbloxen;
	private JLabel label_4;
	private JLabel label_5;
	private JLabel label_6;
	private JSpinner spinner_1;
	private JSpinner spinner_2;
	private JSpinner spinner_3;
	private JSpinner spinner_4;
	private JSpinner spinner_5;
	private JSpinner spinner_6;
	private JLabel lblNewLabel;
	private JLabel lblNewLabel_1;
	private JLabel lblNewLabel_2;
	private JLabel lblNewLabel_3;
	private JLabel lblNewLabel_4;
	private JLabel lblNewLabel_5;
	private JLabel lblNewLabel_6;
	private JLabel lblTotalCost;
	private JLabel lblNewLabel_7;
	private JLabel lblNewLabel_8;
	private JLabel lblNewLabel_9;
	private JLabel lblNewLabel_10;
	private JLabel lblNewLabel_11;
	private JLabel label_7;
	private JLabel label_8;
	private JLabel label_9;
	private JLabel label_10;
	private JLabel label_3;
	private JLabel label_11;
	private JLabel label_12;
	public ShopView()
	{
		htmlStart = "<html><font size=\"4\" color=\"#FFFFFF\"><b>";
		htmlEnd = "</b></font></html>";
		setSize(new Dimension(700,700));
		
		initialize();
	}
	
	public void initialize()
	{
		setLayout(new MigLayout("", "[10:10:10][100px:100px:100px][100px:100px:100px][240px:240px:240px][110px:110px:110px][100px:100px:100px]", "[15:15:15][][][500px:500px:500px][][30:30:30][20:20:20][20:20:20]"));
		SpinnerNumberModel model1 = new SpinnerNumberModel(0, 0, 5000, 1);
		SpinnerNumberModel model2 = new SpinnerNumberModel(0, 0, 5000, 1);
		SpinnerNumberModel model3 = new SpinnerNumberModel(0, 0, 5000, 1);
		SpinnerNumberModel model4 = new SpinnerNumberModel(0, 0, 5000, 1);
		SpinnerNumberModel model5 = new SpinnerNumberModel(0, 0, 5000, 1);
		SpinnerNumberModel model6 = new SpinnerNumberModel(0, 0, 5000, 1);
		SpinnerNumberModel model = new SpinnerNumberModel(0, 0, 5000, 1);
		
		JLabel lblCurrentMoney = new JLabel(htmlStart+"Current Money:"+htmlEnd);
		add(lblCurrentMoney, "flowx,cell 1 1");
		
		currentMoney = new JLabel("New label");
		add(currentMoney, "cell 2 1");
		
		JPanel panel = new JPanel();
		panel.setOpaque(false);
		panel.setBorder(new TitledBorder(null, "Items For Sale", TitledBorder.LEADING, TitledBorder.ABOVE_TOP, null, Color.WHITE));
		add(panel, "cell 1 3 2 1,grow");
		panel.setLayout(new MigLayout("", "[110px:110px:110px][][10:10:10][]", "[][10px:10:10px][][10:10:10][][10:10:10][][10:10:10][][10:10:10][][10:10:10][][10:10:10][][5:5:5][][5:5:5][60:60.00:60]"));
		
		label_7 = new JLabel("");
		label_7.setIcon(new ImageIcon("resources\\Food_Icon.gif"));
		panel.add(label_7, "flowx,cell 0 0");
		
		label = new JLabel("<html><font size=\"4\" color=\"#FFFFFF\">Food:</font></html>");
		panel.add(label, "cell 0 0");
		spinner = new JSpinner(model);
		panel.add(spinner, "cell 1 0,grow");
		
		lblNewLabel = new JLabel("New label");
		panel.add(lblNewLabel, "cell 3 0");
		
		label_8 = new JLabel("");
		label_8.setIcon(new ImageIcon("resources\\Clothes_Icon.gif"));
		panel.add(label_8, "flowx,cell 0 2");
		
		label_1 = new JLabel("<html><font size=\"4\" color=\"#FFFFFF\">Clothes</font></html>");
		panel.add(label_1, "cell 0 2");
		
		spinner_1 = new JSpinner(model1);
		panel.add(spinner_1, "cell 1 2,grow");
		
		lblNewLabel_1 = new JLabel("New label");
		panel.add(lblNewLabel_1, "cell 3 2");
		
		label_9 = new JLabel("");
		label_9.setIcon(new ImageIcon("resources\\Ammo_Icon.gif"));
		panel.add(label_9, "flowx,cell 0 4");
		
		label_2 = new JLabel("<html><font size=\"4\" color=\"#FFFFFF\">Ammo:</font></html>");
		panel.add(label_2, "cell 0 4");
		
		spinner_2 = new JSpinner(model2);
		panel.add(spinner_2, "cell 1 4,grow");
		
		lblNewLabel_2 = new JLabel("New label");
		panel.add(lblNewLabel_2, "cell 3 4");
		
		label_10 = new JLabel("");
		label_10.setIcon(new ImageIcon("resources\\Oxen_Icon.gif"));
		panel.add(label_10, "flowx,cell 0 6");
		
		lbloxen = new JLabel("<html><font size=\"4\" color=\"#FFFFFF\">Hell Hound:</font></html>");
		panel.add(lbloxen, "cell 0 6");
		
		spinner_3 = new JSpinner(model3);
		panel.add(spinner_3, "cell 1 6,grow");
		
		lblNewLabel_3 = new JLabel("New label");
		panel.add(lblNewLabel_3, "cell 3 6");
		
		label_3 = new JLabel("");
		label_3.setIcon(new ImageIcon("resources\\Wheel_Icon.gif"));
		panel.add(label_3, "flowx,cell 0 8");
		
		label_4 = new JLabel("<html><font size=\"4\" color=\"#FFFFFF\">Wheels:</font></html>");
		panel.add(label_4, "cell 0 8");
		
		spinner_4 = new JSpinner(model4);
		panel.add(spinner_4, "cell 1 8,grow");
		
		lblNewLabel_4 = new JLabel("New label");
		panel.add(lblNewLabel_4, "cell 3 8");
		
		label_11 = new JLabel("");
		label_11.setIcon(new ImageIcon("resources\\Tongue_Icon.gif"));
		panel.add(label_11, "flowx,cell 0 10");
		
		label_5 = new JLabel("<html><font size=\"4\" color=\"#FFFFFF\">Tongues:</font></html>");
		panel.add(label_5, "cell 0 10");
		
		spinner_5 = new JSpinner(model5);
		panel.add(spinner_5, "cell 1 10,grow");
		
		lblNewLabel_5 = new JLabel("New label");
		panel.add(lblNewLabel_5, "cell 3 10");
		
		label_12 = new JLabel("");
		label_12.setIcon(new ImageIcon("resources\\Axel_Icon.gif"));
		panel.add(label_12, "flowx,cell 0 12");
		
		label_6 = new JLabel("<html><font size=\"4\" color=\"#FFFFFF\">Axels:</font></html>");
		panel.add(label_6, "cell 0 12");
		
		spinner_6 = new JSpinner(model6);
		panel.add(spinner_6, "cell 1 12,grow");
		
		lblNewLabel_6 = new JLabel("New label");
		panel.add(lblNewLabel_6, "cell 3 12");
		
		lblTotalCost = new JLabel(htmlStart+"Total Cost:"+htmlEnd);
		panel.add(lblTotalCost, "cell 0 14");
		buyButton = new JButton("Buy");
		
		lblNewLabel_7 = new JLabel("New label");
		panel.add(lblNewLabel_7, "cell 1 14,alignx right");
		
		lblNewLabel_10 = new JLabel(htmlStart+"Weight of items:"+htmlEnd);
		panel.add(lblNewLabel_10, "cell 0 16");
		
		lblNewLabel_11 = new JLabel("New label");
		panel.add(lblNewLabel_11, "cell 1 16,alignx right");
		panel.add(buyButton, "cell 0 18 4 1,grow");
		
		JPanel panel_1 = new JPanel();
		panel_1.setOpaque(false);
		panel_1.setBorder(new TitledBorder(null, "Current Inventory", TitledBorder.LEADING, TitledBorder.ABOVE_TOP, null, Color.WHITE));
		add(panel_1, "cell 4 3 2 2,grow");
		panel_1.setLayout(new MigLayout("", "[][][]", "[][25:25:25][][25:25:25][][25:25:25][][25:25:25][][25:25:25][][25:25:25][][25:25:25][][110px:110px:110px]"));
		
		JLabel lblFood = new JLabel(htmlStart+"Food:"+htmlEnd);
		panel_1.add(lblFood, "cell 0 0");
		
		currentFood = new JLabel("New label");
		panel_1.add(currentFood, "cell 2 0");
		
		JLabel lblClothes = new JLabel(htmlStart+"Clothes"+htmlEnd);
		panel_1.add(lblClothes, "cell 0 2");
		
		currentClothes = new JLabel("New label");
		panel_1.add(currentClothes, "cell 2 2");
		
		JLabel lblAmmo = new JLabel(htmlStart+"Ammo:"+htmlEnd);
		panel_1.add(lblAmmo, "cell 0 4");
		
		currentAmmo = new JLabel("New label");
		panel_1.add(currentAmmo, "cell 2 4");
		
		JLabel lblOxen = new JLabel("<html><font size=\"4\" color=\"#FFFFFF\">Hell Hound:</font></html>");
		panel_1.add(lblOxen, "cell 0 6");
		
		currentOxen = new JLabel("New label");
		panel_1.add(currentOxen, "cell 2 6");
		
		JLabel lblWheels = new JLabel(htmlStart+"Wheels:"+htmlEnd);
		panel_1.add(lblWheels, "cell 0 8");
		
		currentWheels = new JLabel("New label");
		panel_1.add(currentWheels, "cell 2 8");
		
		JLabel lblTongue = new JLabel(htmlStart+"Tongues:"+htmlEnd);
		panel_1.add(lblTongue, "cell 0 10");
		
		currentTongues = new JLabel("New label");
		panel_1.add(currentTongues, "cell 2 10");
		
		JLabel lblAxels = new JLabel(htmlStart+"Axels:"+htmlEnd);
		panel_1.add(lblAxels, "cell 0 12");
		
		currentAxels = new JLabel("New label");
		panel_1.add(currentAxels, "cell 2 12");
		
		lblNewLabel_8 = new JLabel(htmlStart+"Total Weight:"+htmlEnd);
		panel_1.add(lblNewLabel_8, "cell 0 14,growx");
		
		lblNewLabel_9 = new JLabel("New label");
		panel_1.add(lblNewLabel_9, "cell 2 14");
		
		
		
		nextButton = new JButton("Next");
		add(nextButton, "cell 5 6 1 2,grow");
	}
	public int getFoodAmount() {
		
		return ((Integer)spinner.getValue()).intValue();
	}


	public void setMoney(int money) {
		currentMoney.setText(htmlStart+"$" + money+htmlEnd);	
	}

	public void setAmmo(int current) {
		currentAmmo.setText(htmlStart+current +htmlEnd);
		
	}

	public void setFood(int current) {
		currentFood.setText(htmlStart+current + htmlEnd);
		
	}

	public void setClothes(int current) {
		currentClothes.setText(htmlStart+current + htmlEnd);
		
	}

	public void setOxen(int current) {
		currentOxen.setText(htmlStart+current + htmlEnd);
		
	}

	public void setWheels(int current) {
		currentWheels.setText(htmlStart+current + htmlEnd);
		
	}

	public void setTongues(int current) {
		currentTongues.setText(htmlStart+current +htmlEnd);
		
	}

	public void setAxels(int current) {
		currentAxels.setText(htmlStart+current +htmlEnd);
		
	}

	public void setBuyListener(ActionListener listen) {
		buyButton.addActionListener(listen);
		
	}

	public void setBackListener(ActionListener listen) {
		
		
	}

	public void setNextListener(ActionListener listen) {
		nextButton.addActionListener(listen);
		
	}

	public int getClothesAmount() {
		return ((Integer)spinner_1.getValue()).intValue();
	}

	public int getAmmoAmount() {
		return ((Integer)spinner_2.getValue()).intValue();
	}

	public int getOxenAmount() {
		return ((Integer)spinner_3.getValue()).intValue();
	}

	public int getWheelAmount() {
		return ((Integer)spinner_4.getValue()).intValue();
	}

	public int getTongueAmount() {
		return ((Integer)spinner_5.getValue()).intValue();
	}

	public int getAxelAmount() {
		return ((Integer)spinner_6.getValue()).intValue();
	}

	public void setFoodPrice(double price) {
		lblNewLabel.setText(htmlStart+"$"+price+"/pound"+htmlEnd);
		
	}
	

	public void setClothesPrice(double price) {
		lblNewLabel_1.setText(htmlStart+"$"+price+"/outfit"+htmlEnd);
		
	}

	public void setAmmoPrice(double price) {
		lblNewLabel_2.setText(htmlStart+"$"+price+"/cartiridge"+htmlEnd);	
		
	}
	
	public void setOxenPrice(double price) {
		lblNewLabel_3.setText(htmlStart+"$"+price+"/yoke"+htmlEnd);
		
	}

	public void setWheelsPrice(double price) {
		lblNewLabel_4.setText(htmlStart+"$"+price+"/wheel"+htmlEnd);
		
	}

	public void setTonguesPrice(double price) {
		lblNewLabel_5.setText(htmlStart+"$"+price+"/tongue"+htmlEnd);
		
	}

	public void setAxelsPrice(double price) {
		lblNewLabel_6.setText(htmlStart+"$"+price+ "/axel" +htmlEnd);
		
	}

	public void setCost(int cost) {
		lblNewLabel_7.setText(htmlStart+"$"+cost+htmlEnd);
		
	}

	public void setCostListener(ChangeListener listen) {
		spinner.addChangeListener(listen);
		spinner_1.addChangeListener(listen);
		spinner_2.addChangeListener(listen);
		spinner_3.addChangeListener(listen);
		spinner_4.addChangeListener(listen);
		spinner_5.addChangeListener(listen);
		spinner_6.addChangeListener(listen);
		
		
	}

	public void setInventoryWeight(int current, int max) {
		lblNewLabel_9.setText(htmlStart+ current + " / " + max + htmlEnd);
		
	}

	public void setBuyWeight(int weight) {
		lblNewLabel_11.setText(htmlStart + weight + htmlEnd);
		
	}

	public boolean listenersExist() {
		if(buyButton.getActionListeners().length > 0)
		{
			return true;
		}
		return false;
	}

	@Override
	public void resetValues() {
		spinner.setValue(0);
		spinner_1.setValue(0);
		spinner_2.setValue(0);
		spinner_3.setValue(0);
		spinner_4.setValue(0);
		spinner_5.setValue(0);
		spinner_6.setValue(0);
	}

	@Override
	public void removeListeners() {
		
		buyButton.removeActionListener(buyButton.getActionListeners()[0]);
		
		nextButton.removeActionListener(nextButton.getActionListeners()[0]);
		
		
	}
	
	public void paintComponent(Graphics g) {
		ImageIcon img = new ImageIcon("resources\\stone_texture.png");
	    g.drawImage(img.getImage(), 0, 0, null);
	  }


}
